package com.edu.edu.day45_mvp.presenter;

import android.os.Handler;

import com.edu.edu.day45_mvp.model.ILoginOnListener;
import com.edu.edu.day45_mvp.model.LoginBiz;
import com.edu.edu.day45_mvp.view.ILoginView;

/**
 * Created by Administrator on 10/9 0009.
 */
public class LoginPresenter {

    private LoginBiz mLoginBiz;
    private ILoginView mView;

    public LoginPresenter(ILoginView view){
        this.mView = view;
        mLoginBiz = new LoginBiz();
    }

    private Handler mHandler = new Handler();

    //登录方法
    public void login(){
        //显示进度条
        mView.showProgressBar();

        mLoginBiz.login(mView.getUserName(), mView.getPassWord(), new ILoginOnListener() {
            @Override
            public void loginSucceed() {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        mView.loginSucceedActivity();
                        mView.hideProgressBar();
                    }
                });

            }

            @Override
            public void loginFailed() {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        mView.loginFialedView();
                        mView.hideProgressBar();
                    }
                });
            }
        });

    }
    //清除方法
    public void clear(){
        mView.clearMsg();
    }
}
